package Practice;

public class Node_Test
{
	public static void removeAfter(Node<Object> node)
	{
		if (node != null && node.nextNode != null)
		{
			node.nextNode = node.nextNode.nextNode;
		}
	}

	public static void insertAfter(Node<Object> first, Node<Object> second)
	{
		Node<Object> lastNode = first;
		if (first != null || second != null)
		{
			while (lastNode.nextNode != null)
			{
				lastNode = lastNode.nextNode;
			}
			lastNode.nextNode = second;
		}
	}

	public static void remove(Node<String> node, String key)
	{
		Node<String> headNode = new Node<String>();
		headNode.nextNode = node;
		node = headNode;
		while (node.nextNode != null)
		{
			if (node.nextNode.item.equals(key))
			{
				node.nextNode = node.nextNode.nextNode;
			} else
			{
				node = node.nextNode;
			}
		}
		node = headNode.nextNode;
	}

	public static Integer max(Node<Integer> node)
	{
		if (node == null)
			return 0;
		int maxKey = node.item;
		Node<Integer> temp = node;
		while (temp != null)
		{
			maxKey = maxKey > node.item ? maxKey : node.item;
			temp = temp.nextNode;
		}
		return maxKey;
	}

	public static int maxs(Node<Integer> node)
	{
		if (node == null)
		{
			return 0;
		}
		int max = maxs(node.nextNode);
		return node.item > max ? node.item : max;
	}
}

class Node<Item>
{
	Item item;
	Node<Item> nextNode;
}
